var hour_offset;
var min_offset;
var sec_offset;

//clock function for the main page
function servertime(hour, min, sec)
{
	var currentTime = new Date()

	//calculate the difference between the server time and client time
	hour_offset = hour - currentTime.getHours();
	min_offset = min - currentTime.getMinutes();
	sec_offset = sec - currentTime.getSeconds();
	
	//call the clock
	clock();
}

function clock()
{
	//this will be synced with server time when we add php
	//get client date
	var currentTime = new Date();
	
	var adjusted = currentTime.getTime();
	adjusted += 216000* hour_offset;//adjust hours
	adjusted += 3600 * min_offset;//adjust min
	adjusted += 60 * sec_offset;//adjust sec
	currentTime.setTime(adjusted);//set the time structure to the adjusted time
	
	//get hours, min, sec and format
	var hour = currentTime.getHours();
	var period = "AM";
	if( hour < 10 )
	{
		hour = '0' + hour;
	}
	if( hour >= 12 )
	{
		period = "PM";
	}
	if(hour > 12)
	{
		hour -= 12;
	}
		
	var min = currentTime.getMinutes();
	if( min < 10 )
	{
		min = '0' + min;
	}
	var sec = currentTime.getSeconds();
	if( sec < 10 )
	{
		sec = '0' + sec;
	}
	
	//set the "clock" div's html to the value of the time
	document.getElementById("clock").innerHTML = hour + ":" + min + ":" + sec + " " + period;         

	//recursively call the function every second
	setTimeout("clock();", 1000);
}
